/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ez2find.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;

/**
 *
 * @author org.@le
 */
@NamedQuery(name = "selectForums", query = "SELECT f FROM Forum f")
@Entity              
public class Forum implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date creationDate;
    private String description;
    @OneToMany(mappedBy = "forum", cascade = CascadeType.REMOVE)
    private List<Topic> topics;
    @ManyToOne
    private RegisterUser user;

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public RegisterUser getUser() {
        return user;
    }

    public void setUser(RegisterUser user) {
        this.user = user;
    }

    public List<Topic> getTopics() {
        if (topics==null){
            topics=new ArrayList<Topic>();
        }
        return topics;
    }

    public void setTopics(List<Topic> topics) {
        this.topics = topics;
    }
    
    public int getTopicsSize() {
        return getTopics().size();
        
    }
    
    public int getMessageMessages(Message m){
        
        if (m.getMessages().isEmpty()){
            return 1;
        
        }else{
            int cont=1;
            for (Message me:m.getMessages()){
                cont=cont+getMessageMessages(me);
            }
        return cont;
        }
        
    }
    
    public int getMessagesSize(){
        int suma=0;
        for (Topic t:getTopics()){
            for (Message m:t.getMessages()){
                suma=suma+getMessageMessages(m);
            }
            
        }
        return suma;
    }

}
